import config from "config";
import httpFetch from "share/httpFetch";
import errorMessage from "share/errorMessage";

export default {
  //审核通过
  auditPass(params) {
    return httpFetch.post(`${config.baseUrl}/api/audit/pass`, params, {}, { timeout: 180000 });
  },

  //审核拒绝
  auditReject(params) {
    return httpFetch.post(`${config.baseUrl}/api/audit/reject`, params);
  },

  //审核通知
  noticeApplication(params) {
    return httpFetch.post(`${config.baseUrl}/api/approval/send/notice`, params);
  },

  //审核图片
  checkAttachment(params) {
    return httpFetch.post(`${config.baseUrl}/api/audit/image/checked`, params);
  },

  //扫码枪审核
  scan(code) {
    let params = {
      code,
      operate: "AUDIT",
    };
    return httpFetch.post(`${config.baseUrl}/api/audit/scancode`, params);
  },

  //发票袋查询
  getExpCodeOption(expenseReportBagCode, isAudit) {
    return httpFetch.get(
      `${config.baseUrl}/api/expense/reports/bag/fuzzy/query?expenseReportBagCode=${expenseReportBagCode}&isAudit=${isAudit}`
    );
  },

  //报销单内发票
  getExpenseReportInvoices(expenseReportOID) {
    return httpFetch
      .get(`${config.baseUrl}/api/expense/reports/receipt/finance/query`, {
        expenseReportOID,
      })
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

  //得到发票详情
  getInvoiceDetail(receiptId) {
    return httpFetch
      .get(`${config.baseUrl}/api/receipt/query/${receiptId}`)
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

  //OCR扫描发票图片
  scanBase64(imageData, entityId) {
    return httpFetch
      .post(`${config.baseUrl}/api/expense/reports/bag/receipt/scan`, {
        imageData,
        entityId,
        entityType: "expense_report",
      })
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

  //删除财务发票
  deleteFinanceInvoice(receiptId) {
    return httpFetch
      .delete(`${config.baseUrl}/receipt/api/receipts/${receiptId}`)
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

  //得到批注
  getAnnotateByEntityOID(entityOID, type) {
    return httpFetch
      .get(`${config.baseUrl}/api/report/note/${entityOID}`, { type })
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

  //新增批注
  addAnnotate(params) {
    return httpFetch
      .post(`${config.baseUrl}/api/report/note/save`, params)
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

  //删除批注
  deleteAnnotate(noteId) {
    return httpFetch
      .delete(`${config.baseUrl}/api/report/note/${noteId}`)
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

  //核对发票
  checkInvoice(params) {
    return httpFetch
      .post(`${config.baseUrl}/api/audit/receipt/checked`, params)
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

  //单笔驳回
  rejectExpense(params) {
    return httpFetch
      .post(`/api/audit/reject/expensereport/invoice`, params)
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

  //报销单核对发票
  expenseCheckInvoice(expenseReportOID) {
    return httpFetch
      .put(
        `/api/expense/reports/receipt/check?expenseReportOID=${expenseReportOID}`
      )
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

  //获取人工核对信息 type: NOT_MATCHED(未匹配)，TO_BE_CHECKED(待核对)
  getManualCheckInfo(entityOID, type, entityType) {
    let url =
      entityType === 5001
        ? "/api/expense/report/bag/manual/check"
        : "/api/expense/report/manual/check";
    let params =
      entityType === 5001
        ? { expenseReportBagCode: entityOID, type }
        : { expenseReportOID: entityOID, type };
    return httpFetch.get(url, params);
  },

  //人工发票匹配／核对
  manualCheck(params, entityType) {
    let url =
      entityType === 5001
        ? "/api/expense/report/bag/manual/check"
        : "/api/expense/report/manual/check";
    return httpFetch.post(url, params);
  },

  //获取通知的发票信息
  getNoticeInfo(entityOID, entityType) {
    let url =
      entityType === 5001
        ? "/api/expense/report/bag/notice/message"
        : "/api/expense/report/notice/message";
    let params =
      entityType === 5001
        ? { expenseReportBagCode: entityOID }
        : { expenseReportOID: entityOID };
    return httpFetch.get(url, params);
  },

  getAuditFlag(params) {
    return httpFetch.get("/api/audit/flag", params);
  },

  //扫码枪审核 start
  // 单据
  scan(params) {
    return httpFetch.post(`${config.baseUrl}/api/audit/scancode`, params);
  },
  // 发票袋
  scanBag(params) {
    return httpFetch.post(
      `${config.baseUrl}/api/expense/reports/bag/web/scancode`,
      params
    );
  },
  // 发票袋驳回
  rejectBag(params) {
    return httpFetch.post(
      `${config.baseUrl}/api/expense/reports/bag/scan/reject`,
      params
    );
  },

  //审核驳回：发票袋／单据
  rejectAudit(params) {
    return httpFetch.post(`/api/audit/scan/reject`, params);
  },

  // 移除发票袋关联关系
  deleteBagRelation(params) {
    return httpFetch
      .post(`/api/expense/report/bag/delete/relation`, params)
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },
  //智能审核
  autoAudit(params) {
    return httpFetch.post(`/api/audit/scancode`, params);
  },
  //获取是否显示智能审核字段
  getSmartAuditField() {
    return httpFetch.get("/api/finance/autoAudit/query/bookset/rule");
  },

  // 获取报销单或对公支付单待审核数量接口
  getExpenseAuditCount(params) {
    return httpFetch.get(`/api/expense/reports/pending/audit/count`, params);
  },

  // 获取借款单待审核数量接口
  getLoanAuditCount() {
    return httpFetch.get(`/api/loanBill/pending/audit/count`);
  },
  // 卷票机审核识别发票
  scanAuditReceipt(params) {
    return httpFetch.post(`/api/expense/report/receipt/audit/scan`, params);
  },
  // 发票添加至报销单
  addReceiptToClaim(params) {
    return httpFetch.post(`/api/expense/report/receipt/audit/import`, params);
  },
};
